        <%@ page import="db.DBConnection" %>
<%@ page import="db.User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="db.Account" %>
<%@ page import="db.HistoryUnit" %>
<%
    int user_id = -1;
    String secret1 = "";
    Cookie[] cookies = request.getCookies();

    for (Cookie cookie : cookies) {
        if (cookie.getName().equals("user_id")) {
            user_id = Integer.parseInt(cookie.getValue());
        } else if (cookie.getName().equals("secret")) {
            secret1 = cookie.getValue();
        }
    }
    DBConnection dbConnection = new DBConnection();
    if (!dbConnection.isCookieOk(user_id, secret1)) {
        String redirectURL = "index.jsp";
        response.sendRedirect(redirectURL);
        return;
    }
    int num = dbConnection.doGetNumberOfUnreadMessages(user_id);
%>

<%--
  Created by IntelliJ IDEA.
  User: user
  Date: 07.05.12
  Time: 19:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Mobile</title>
    <link rel="stylesheet" type="text/css" href="style"/>
    <%
        String account_from = request.getParameter("account_from");
        String operator = request.getParameter("operator");
        String phone_number = request.getParameter("phone_pref") + request.getParameter("phone_number");
        String amount = request.getParameter("amount");
        double money = 0;
        try {
            if (amount != null) {
                money = Double.parseDouble(amount);
            }
        } catch (NumberFormatException e) {
            money = -1111111111;
        }
        boolean isOk = false;
        boolean hasParams = false;

        if (account_from != null && operator != null && phone_number != null && amount != null) {
            hasParams = true;
            if (money == -1111111111) {
                isOk = false;
            } else {
                isOk = dbConnection.doPayForMobile(user_id, account_from, DBConnection.Mobile_Operator.valueOf(operator), phone_number, money);
            }
        }
    %>
</head>
<body>
<div class="logout" style="text-align:right;"><a href="logout.jsp">  Logout</a></div>
<div class="header"><img src="logo.jpg"></div>
<div class="layout">
    <div class="sidebar">
        <ul class="cssmenu">
            <li><a href="personal_info.jsp">Personal info</a></li>
            <li><a href="accounts.jsp">Accounts</a></li>
            <li><b><a href="operations.jsp">Operations</a></b></li>
            <li><a href="messages.jsp">Messages<% if (num != 0) {%> <b> (<%=num%>)</b> <%}%></a></li>
        </ul>
    </div>
    <%
        ArrayList<Account> accounts = dbConnection.getAccounts(user_id, user_id, DBConnection.OwnerType.CLIENT);
    %>
    <div class="content">

        <% if (hasParams) {
            if (isOk) {
        %> <p style="color: green;"> Payment completed! </p> <%
    } else {
    %> <p style="color: red;"> Payment failed! </p><%
            }
        } %>
        <form method="post" action="mobile.jsp">
            <table class="table">
                <tr>
                    <td width="150"> Account from: <font color="red">*</font></td></td>
                    <td width="100"> <select name="account_from">
                        <% for (Account account : accounts) {%>
                        <option value=<%=account.number+" ("+account.money+"руб.)"%>> <%=account.number+" ("+account.money+"руб.)"%> </option>
                        <% } %>
                    </select>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td width="150"> Phone operator: <font color="red">*</font></td></td>
                    <td width="100"> <select name="operator">
                    <% for (DBConnection.Mobile_Operator str : DBConnection.Mobile_Operator.values()) {%>
                    <option value=<%=str.toString()%>> <%=str.toString()%> </option>
                    <% } %>
                    </select>
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td width="150"> Phone number: <font color="red">*</font></td></td>
                    <td> <input type="text" name="phone_pref" size="3">
                         <input type="text" name="phone_number" size="5">
                    </td>
                    <td style="color: gray;" width="100" style="text-align:left;" > 963-3456280 </td>
                </tr>
                <tr>
                    <td width="100"> Amount: <font color="red">*</font></td></td>
                    <td> <input type="text" name="amount" size="15"></td>
                    <td></td>
                </tr>
            </table>
            <input type="submit" value="Pay for mobile!">
        </form>
    </div>
</div>
</body>
</html>